package libs

import (
	"fmt"
)

// 定义父类：接口类——本质是一个指针
type AnimalIF interface {
	Sleep()
	GetColor() string
	GetKind() string
}

// 定义具体的子类
type Animal struct {
	name  string
	color string
	kind  string
}

type Cat struct {
	Animal
}

type Dog struct {
	Animal
}

// 定义Cat方法，实现AniamlIF里面所有的
func (c Cat) Sleep() {
	fmt.Println(c.name, " is sleeping")
}

func (c Cat) GetColor() string {
	return c.color
}

func (c Cat) GetKind() string {
	return c.kind
}

// 定义Dog方法
func (d Dog) Sleep() {
	fmt.Println(d.name, " is sleeping")
}

func (d Dog) GetColor() string {
	return d.color
}

func (d Dog) GetKind() string {
	return d.kind
}

// 接口参数
func showInfo(animal AnimalIF) {
	animal.Sleep()
	fmt.Println("颜色：", animal.GetColor())
	fmt.Println("种类：", animal.GetKind())
}

func AnimalShow() {
	var catRed Cat
	catRed.name = "花花"
	catRed.color = "red"
	catRed.kind = "Cat"

	var dogBlue Dog
	dogBlue.name = "旺财"
	dogBlue.color = "yellow"
	dogBlue.kind = "Dog"

	// 多态1
	var animal AnimalIF = &catRed
	animal.Sleep()
	animal = &dogBlue
	animal.Sleep()

	// 多态2
	showInfo(&catRed)
	showInfo(&dogBlue)
}
